package top.drinyeit.weilong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import java.util.List;

import top.drinyeit.weilong.R;
import top.drinyeit.weilong.model.PictureBean;

/**
 * Created by wu on 2018/1/10.
 */

public class CommodityDetailBottomAdapter extends RecyclerView.Adapter<CommodityDetailBottomAdapter.ViewHolder> {

    private Context context;
    private List<PictureBean> list;

    public CommodityDetailBottomAdapter(List<PictureBean> list){
        this.list = list;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public ImageView img;
        public ViewHolder(View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.img);
        }
    }

    @Override
    public CommodityDetailBottomAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View v = LayoutInflater.from(context).inflate(R.layout.item_home_more, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(CommodityDetailBottomAdapter.ViewHolder holder, int position) {
        Glide.with(context).load(list.get(position).getPicture_url())
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .dontTransform()
                .placeholder(R.drawable.ic_def)
                .placeholder(R.drawable.ic_def)
                .into(holder.img);
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }
}
